unit frmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TMainForm = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    OpenDialog1: TOpenDialog;
    GroupBox1: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    SaveDialog1: TSaveDialog;
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  MainForm: TMainForm;

implementation

uses frmAbout;

{$R WindowsXP.res}
{$R *.dfm}


procedure TMainForm.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then begin
Edit1.Text:=OpenDialog1.FileName;
Button2.Enabled:=True;
end;
end;


function attacher(input:string;output:string):boolean;
var
  SFX,BatchF: TMemoryStream;
  iSize,i:integer;
  Hidden:Byte;
  Buffer:Array of byte;
  p:pointer;
begin
  SFX := TMemoryStream.Create;
  SFX.LoadFromFile(ExtractFilePath(ParamStr(0))+'SFX.dll');
  SFX.Seek(0,soFromEnd);
  try
  BatchF:= TMemoryStream.Create;
  BatchF.LoadFromFile(input);
  //------------------------------
    SetLength(Buffer,BatchF.Size);
    p:=Buffer;
    BatchF.Read(p^,BatchF.Size);
    for i:=0 to BatchF.Size do
    Buffer[i]:=Buffer[i]+50;
    SFX.Seek(0, soFromEnd);
    SFX.Write(p^, BatchF.Size);
    iSize := BatchF.Size + SizeOf(Integer)+1;
  //---------------

   SFX.Write(iSize, SizeOf(iSize));
   if MainForm.RadioButton2.Checked then
    Hidden:=1
    else
    Hidden:=0;
   SFX.Write(Hidden,1);
   SFX.SaveToFile(output);
   result:=true;
   except
   result:=false;
   end;
  SFX.Free;
end;

procedure TMainForm.Button4Click(Sender: TObject);
begin
Close;
end;

procedure TMainForm.FormCreate(Sender: TObject);
var
exe:string;
begin
if (ParamStr(1)<>'') then begin
exe:=copy(ParamStr(1),0,Length(ParamStr(1))-Length(ExtractFileExt(ParamStr(1))))+'.exe';
if attacher(ParamStr(1),exe) then
else begin
ShowMessage('Error in Process');
Application.Terminate;
end;
end else
MainForm.Show;
end;

procedure TMainForm.Button2Click(Sender: TObject);
begin
if SaveDialog1.Execute then
if attacher(edit1.Text,SaveDialog1.FileName) then
ShowMessage('Done')
else
ShowMessage('Error in Process');
end;

procedure TMainForm.Button3Click(Sender: TObject);
begin
About.ShowModal;
end;

end.
